<template>
  <div>
    <Panel title="费率映射管理" useBack>
         <ModifyForm
        slot="body"
        :editColumn="editColumn"
        :temporaryData='temporaryData'
        labelWidth="150px"
        :updateData="updateData"
      >
        <p
          slot="title"
        ></p>
      </ModifyForm>
    </Panel>
  </div>
</template>
<script>
import Panel from "@/components/Panel";
import ModifyForm from "@/components/ModifyForm";
import ModalPanel from "@/components/ModalPanel";
import request from "@/tools/request";

export default {
  name:'companyRateInfo',
  components: {
    Panel,
    ModalPanel,
    ModifyForm
  },
  data() {
    return {
     configValue:"",
      editorOption: {},
      typeList: [],
      temporaryData: {
        coverImg: [],
        publishStatus: false
      },
      editColumn: [
          {
          name: "集团大客户",
          prop: "groupId",
          type: "select",
          optionBindLabel: 'name',
          optionBindValue: 'id',
          optionList: [{'id':'','name':'请选择'}],
          onChange: (val) => {},
          required:true,
          width:24
        },
        {
          name: "站点",
          prop: "siteId",
          type: "select",
          optionBindLabel: 'name',
          optionBindValue: 'id',
          optionList: [{'id':'','name':'请选择站点'}],
          onChange: () => {},
          required:true,
          width:24
        },
        {
          name: "费率组",
          prop: "rateGroupId",
          type: "select",
          optionBindLabel: 'name',
          optionBindValue: 'id',
          optionList: [{'id':'','name':'请选择费率组'}],
          onChange: () => {},
          required:true,
          width:24
        },
      ],
    };
  },
  computed: {
 

  },
  methods: {
   async updateData(values) {
     let url, msg
     const { siteId, rateGroupId, id, groupId } = values
     if(id){
        url = '/rate/group/map/update'
        msg = '编辑成功'
     }else{
        url = '/rate/group/map/add'
        msg = '添加成功'
     }
     
      let res = await request({
        url: url,
        method: "POST",
        data: { siteId, rateGroupId, id, groupId }
      });
      if (res.code !== 0) return
      this.$message.success(msg)
      this.$router.go(-1)
    },
    setSite(val){
    },
    async fetchData(id){
      let { rateMap } = await request({
        url: "/rate/group/map/info/"+id,
        method: "GET",
        data: {}
      });
      this.temporaryData = rateMap
    },
    //站点
    async iotSite(){
      let { list } = await request({
      url: "/iot/site/select",
      method: "POST",
      data: {}
      });
      this.editColumn[1].optionList = list
    },
    async company(){
      let { list } = await request({
      url: "/company/group/select",
      method: "POST",
      data: {}
      });
      this.editColumn[0].optionList = list
    },
    //费率组
    async getRateList(){
      let { list } = await request({
      url: "/grate/group/all",
      method: "POST",
      data: {}
      });
      this.editColumn[2].optionList = list
    }

  },
  created() {
    if(this.$route.query.id)
      this.fetchData(this.$route.query.id)
      this.iotSite()
      this.getRateList()
      this.company()
  }
};
</script>

<style lang='scss' module>

</style>